﻿@page "/Bas/Goods/BatchEdit"
@using nERP.ViewModel.Bas.GoodsVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <div style="margin-bottom:10px;"> @WtmBlazor.Localizer["Sys.BatchEditConfirm"]</div>
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsName" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsSpec" />
        <Select @bind-Value="@Model.LinkedVM.GoodsTypeId" Items="AllGoodsTypes" />
        <Select @bind-Value="@Model.LinkedVM.GoodsUnitId" Items="AllGoodsUnits" IsPopover ShowSearch />
        <BootstrapInput @bind-Value="@Model.LinkedVM.RestockingPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.RetailPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.WholesalePrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.SafetyStock" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.Remark" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.Stock" />
    </Row>

    <div class="modal-footer table-modal-footer">
        <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
        <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
    </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private GoodsBatchVM Model = new GoodsBatchVM();
    private ValidateForm vform { get; set; }

    private async Task Submit(EditContext context)
    {
        Model.Ids = ids;
        await PostsForm(vform, "/api/Bas/Goods/BatchEdit", (s) => WtmBlazor.Localizer["Sys.BatchEditSuccess", s], method: HttpMethodEnum.POST);
    }


    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllGoodsTypes = new List<SelectedItem>();
    private List<SelectedItem> AllGoodsUnits = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllGoodsTypes = await WtmBlazor.Api.CallItemsApi("/api/Bas/Goods/GetGoodsClasss");
        AllGoodsTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodsUnits = await WtmBlazor.Api.CallItemsApi("/api/Bas/Goods/GetComputationUnits");
        AllGoodsUnits.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });

        await base.OnInitializedAsync();
    }
}
